<?php
/**
 * @file productindexcontroller.php $
 * @author LinLin (linlin@haibao.com) $
 * @date 2017-11-30 下午2:41:51 $
 * @brief  $
 */
namespace haibao\cms\business\control\pc\channel\product;

class ProductIndexController extends ProductController{
	public function __construct($updateTime = null,$controlId,$isPublish){
		parent::__construct($updateTime,$controlId,$isPublish);
	}

	public function displayTemplateHtml(){
		$controlData = $this->getParameter(self::$CONTROL_DATA);
		$content = $this->getParameter(self::$CONTROL_CONTENT);
		$path = $this->generateHtmlPath(__CLASS__);
		$endKey = array();
        $categoryParentArr = \haibao\classlibrary\cms\common\Product::getCategoryParentArr();
		
		$productList = $temp = $productGetList = $relateEvaluateInfo = $tryOut = $newFashionGoodsList = $tempProductList = array();

		//最新时尚单品
		if($controlData['manual'] && $controlData['manual']['contorllerType'] == 'product'){
		    $data = self::getProductInstance();
		    //最新发布的48个单品
		    $productGetList = $data->getNewGoodsList();
		    if($productGetList){
		        $temp = array_rand($productGetList,48);
		        foreach ($temp as $k=>$v){
		        	array_push($productList, $productGetList[$v]);
		        }
		        $number = range(0,46,2);
		        foreach($number as $num){
		            $tempProductList[] = array_slice($productList,$num,2);
		        }
		    }
		    //免费试用
		    //评测  3条
		    $relateEvaluateInfo = \haibao\cms\business\Article::getProductRelateArticleInfo('',3);
		    if($relateEvaluateInfo){
		        foreach($relateEvaluateInfo as $key=>$evaluate){
		            $relateEvaluateInfo[$key]['ArticleUrl'] = self::getArticleUrl($evaluate['PublishId'],$evaluate['ParentId'],1);
		        }
		    }
		    //全部正在申请中的试用
		    $tryOut = $data->getTryOut();
		    
		    //最新时尚单品
		    $newFashionGoodsList = $data->getNewFashionGoodsList($categoryParentArr);
		    $endKeyArr = end($newFashionGoodsList);
		    $endKey = array_keys($newFashionGoodsList,$endKeyArr);
		}
		if($endKey){
			$this->assign('endKey', $endKey[0]);
		}else {
			$this->assign('endKey', '');
		}
		$this->assign('productList', $tempProductList);
		$this->assign('relateEvaluateInfo', $relateEvaluateInfo);
		$this->assign('tryOut', $tryOut);
		$this->assign('newFashionGoodsList', $newFashionGoodsList);
		$this->assign('categoryParentArr', $categoryParentArr);

		$this->assign('productHost', \haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::CLASSLIBRARY_CONFIG_HOST_BRANDS));
		$this->assign('tryHost', \haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::CLASSLIBRARY_CONFIG_HOST_TRY));
		
		$isNewHtml = $this->generateHtml($path,$content);
		$content = $this->getHtml($path);
		$content = $this->replaceCDNLink($content);
		return $content;
	}
}